﻿using MexicanControl.model;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using static MexicanControl.model.Save;

namespace MexicanControl
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }
        public static List<GoodsMsg> goodsMsgs = new List<GoodsMsg>();
        private void exit_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (e.ChangedButton == MouseButton.Left && e.ClickCount == 2)
                {
                    MessageBoxResult result = MessageBox.Show("Exit orders will not be made,Do you really want to quit?", "Exit", MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
                    if (result == MessageBoxResult.Yes)
                    {
                        foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                        {
                            if (thisProc.ProcessName == "DuBaiCoffee2")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                            if (thisProc.ProcessName == "MINIGKP")
                            {
                                if (!thisProc.CloseMainWindow())
                                    thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                            }
                        }
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            System.Windows.Application.Current.Shutdown();
                        }));
                    }
                }
            }
            catch (Exception)
            {
                return;
            }

        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ(string robotName, int type)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    if (isRobot)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = robotName;
                        coffeelist.type = type;
                        clientList.message = coffeelist;
                        clientList.code = 3;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ_N(string robotName, int type)
        {
            try
            {
                if (IceSocket != null)
                {
                    ClientList clientList = new ClientList();
                    MessageClientList coffeelist = MessageClientList.Instance;
                    coffeelist.Name = robotName;
                    coffeelist.type = type;
                    clientList.message = coffeelist;
                    clientList.code = 3;
                    IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        ///   状态  0 关状态  1 开状态 2 已开机 3 上电 4 下电 5 已使能 6 下使能 7 已运行 8 继续运行 9 已报警 10 已暂停  11已停止 ,12 机械臂状态查询
        /// </summary>
        /// <param name="robotName"></param>
        /// <param name="type"> </param>
        public void Robot_CZ_Ns(string robotName, int type)
        {
            try
            {
                if (IceSocket != null)
                {
                    ClientList clientList = new ClientList();
                    MessageClientList coffeelist = MessageClientList.Instance;
                    coffeelist.Name = robotName;
                    coffeelist.type = type;
                    clientList.message = coffeelist;
                    clientList.code = 3;
                    IceSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void L_SD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_SD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 2);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_BJ_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BJ.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 9);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_BTSD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BTSD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 3);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_BTXD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_BTXD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 4);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_SSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_SSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 5);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_XSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_XSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 6);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_YXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_YXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 7);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_TZCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_TZCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 11);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_ZTCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_ZTCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 10);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void L_JXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (L_JXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_L", 8);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_SD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_SD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 2);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_BJ_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_BJ.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 9);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_BTSD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_BTSD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 3);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_BTXD_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_BTXD.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 4);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_SSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_SSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 5);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_XSN_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_XSN.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 6);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_YXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_YXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 7);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_TZCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_TZCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 11);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_ZTCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_ZTCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 10);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        private void R_JXCX_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                if (R_JXCX.Tag.ToString() == "1")
                {
                    Robot_CZ("Reload_R", 8);
                }
            }
            catch (Exception)
            {
                return;
            }
        }


        private void Reload_R_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ("Reload_R", 12);
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Reload_L_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ("Reload_L", 12);
            }
            catch (Exception)
            {
                return;
            }
        }

        private void Reload_N_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Robot_CZ_N("Reload_N", 12);
            }
            catch (Exception)
            {
                return;
            }
        }
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Visible;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
                ShangP.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }

        private void CoffeeRobot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Visible;
                ShangP.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NaichaRobot_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                //zhizuo.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }

        private void DDZZ_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                //zhizuo.Visibility = Visibility.Visible;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
            }
            catch (Exception)
            {
                return;
            }
        }
        public void Send(string name, string tag)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    if (isRobot)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = name;
                        coffeelist.type = double.TryParse(tag, out double do1) ? do1 : 0;
                        clientList.message = coffeelist;
                        clientList.code = 0;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void Sends(string name, string tag)
        {
            try
            {
                if (CoffeeSocket != null)
                {
                    if (isRobot)
                    {
                        ClientList clientList = new ClientList();
                        MessageClientList coffeelist = MessageClientList.Instance;
                        coffeelist.Name = name;
                        coffeelist.type = int.TryParse(tag, out int do1) ? do1 : 0;
                        clientList.message = coffeelist;
                        clientList.code = 0;
                        CoffeeSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                    }
                    else
                    {
                        MessageBox.Show("Please update later, the program is loading!");
                    }
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void ICeCLTime_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("ICeCLTime", ICECC_CMB.Text);
            }
            catch (Exception)
            {
                return;
            }
        }
        public static Socket serverSocket;
        public static Socket CoffeeSocket;
        public static Socket IceSocket;
        public static Socket DPSocket;
        private static byte[] result = new byte[2048];
        private static int myProt = 8885;  //端口 
        public static bool ismake = false;
        public static bool isRobot = false;
        public List<ClientList> clientLists = new List<ClientList>();
        public static string IPorPortUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"IPorPortMessage.txt";
        public static string GoodsUrl = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"coffee\GoodsMessage.txt";
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                saveDeviceMatter save = new saveDeviceMatter();
                save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                var saves = JsonConvert.SerializeObject(save);
                HttpMsg.Instance.saveDeviceMatterMsg(saves);
                if (!File.Exists(IPorPortUrl))
                {
                    using (FileStream stream = File.Create(IPorPortUrl))
                    {
                        stream.Close();
                        stream.Dispose();
                        IPorPortInfo porPortInfo1 = IPorPortInfo.Instance;
                        File.WriteAllText(IPorPortUrl, JsonConvert.SerializeObject(porPortInfo1));
                    }
                }
                else
                {
                    var dd = File.ReadAllText(IPorPortUrl);
                    var porPortInfo = JsonConvert.DeserializeObject<IPorPortInfo>(File.ReadAllText(IPorPortUrl));
                    IPorPortInfo.Instance.url_start = porPortInfo.url_start;
                    IPorPortInfo.Instance.DeviceId = porPortInfo.DeviceId;
                    IPorPortInfo.Instance.CoffeeIP = porPortInfo.CoffeeIP;
                }
                try
                {
                    dgvtb.Columns.Add(new DataColumn("sp_Name"));
                    dgvtb.Columns.Add(new DataColumn("sp_Code"));
                    dgvtb.Columns.Add(new DataColumn("CoffeeWZ"));
                    dgvtb.Columns.Add(new DataColumn("CoffeeWZ1"));
                    dgvtb.Columns.Add(new DataColumn("CoffeeWZ2"));
                    dgvtb.Columns.Add(new DataColumn("Sugar"));
                    var GoodsList = JsonConvert.DeserializeObject<List<GoodsMsg>>(File.ReadAllText(GoodsUrl));
                    goodsMsgs.Clear();
                    GoodsList.ForEach(goodsMsgs.Add);
                    DataRow dataRow;
                    dgvtb.Rows.Clear();
                    foreach (var item in goodsMsgs)
                    {
                        dataRow = dgvtb.NewRow();
                        dataRow["sp_Name"] = item.sp_Name;
                        dataRow["sp_Code"] = item.sp_Code;
                        dataRow["CoffeeWZ"] = item.CoffeeWZ;
                        dataRow["CoffeeWZ1"] = item.CoffeeWZ1;
                        dataRow["CoffeeWZ2"] = item.CoffeeWZ2;
                        dataRow["Sugar"] = item.Sugar;
                        dgvtb.Rows.Add(dataRow);
                    }
                    grid1.ItemsSource = dgvtb.DefaultView;
                }
                catch
                {
                }
                IP.Text = IPorPortInfo.Instance.CoffeeIP.Split('.')[2];
                CoffeeMake();

            }
            catch (Exception)
            {
                return;
            }
        }
        #region 服务器链接
        /// <summary>
        /// 服务器启动监听各种信息动态
        /// </summary>
        public void CoffeeMake()
        {
            try
            {

                string LocalIP = "192.168.0.77";
                var host = Dns.GetHostEntry(Dns.GetHostName());
                foreach (var ips in host.AddressList)
                {
                    if (ips.AddressFamily == AddressFamily.InterNetwork)
                    {
                        LocalIP = ips.ToString();
                        // Console.WriteLine"IP Address = " + (ips.ToString());
                    }
                }
                //服务器IP地址 
                IPAddress ip = IPAddress.Parse(LocalIP);
                serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                serverSocket.Bind(new IPEndPoint(ip, myProt)); //绑定IP地址：端口 
                serverSocket.Listen(10);  //设定最多10个排队连接请求 
                Console.WriteLine("启动监听{0}成功", serverSocket.LocalEndPoint.ToString());
                //通过Clientsoket发送数据 
                Thread myThread = new Thread(ListenClientConnect);
                myThread.IsBackground = true;
                myThread.Start();
                Thread thread1 = new Thread(MsgShowServer);
                thread1.IsBackground = true;
                thread1.Start();
                foreach (System.Diagnostics.Process thisProc in System.Diagnostics.Process.GetProcesses())
                {
                    if (thisProc.ProcessName == "DubaiCoffee2")
                    {
                        if (!thisProc.CloseMainWindow())
                            thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                    }
                    //if (thisProc.ProcessName == "MINIGKP")
                    //{
                    //    if (!thisProc.CloseMainWindow())
                    //        thisProc.Kill(); //当发送关闭窗口命令无效时强行结束进程     
                    //}
                }
                Process ps = new Process();
                string yourURL = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"coffee";
                ps.StartInfo.FileName = "DubaiCoffee2.exe";
                ps.StartInfo.WorkingDirectory = yourURL;
                ps.Start();
                Thread.Sleep(1000);
                //Process ps1 = new Process();
                //string yourURL1 = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"显示屏";
                //ps1.StartInfo.FileName = "MINIGKP.exe";
                //ps1.StartInfo.WorkingDirectory = yourURL1;
                //ps1.Start();
            }
            catch (Exception ex)
            {
                serverSocket.Shutdown(SocketShutdown.Both);
                serverSocket.Close();
                CoffeeMake();
                return;
            }
        }
        /// <summary> 
        /// 监听客户端连接 
        /// </summary> 
        private void ListenClientConnect()
        {
            try
            {
                while (true)
                {
                    Socket clientSocket = serverSocket.Accept();
                    string ip = ((IPEndPoint)clientSocket.RemoteEndPoint).Address.ToString();
                    Console.WriteLine("点单");
                    Thread receiveThread = new Thread(ReceiveMessage);
                    receiveThread.IsBackground = true;
                    receiveThread.Start(clientSocket);
                    Thread.Sleep(10);

                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void MsgShowServer()
        {

            try
            {
                while (true)
                {
                    try
                    {
                        if (clientLists.Count > 0)
                        {
                            var making = clientLists[0];
                            if (making != null)
                            {
                                if (making.code == 2)
                                {
                                    CoffeeMsg(making.MsgBol);
                                }
                                else if (making.code == 3)
                                {
                                    if (making.message.Name == "Reload_L")
                                    {
                                        RobotSel_L(making.robotMsg);
                                    }
                                    else if (making.message.Name == "Reload_R")
                                    {
                                        RobotSel_R(making.robotMsg);
                                    }
                                }
                                else if (making.code == 0)
                                {
                                    DOSelect(making.message.Name, making.message.type);
                                }
                                else if (making.code == 12)
                                {
                                    isRobot = true;
                                }
                                else if (making.code == 10)
                                {
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = making.IsMake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                        ismake = making.IsMake;
                                    }
                                }
                            }
                            clientLists.RemoveAt(0);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    Thread.Sleep(100);
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary> 
        /// 接收消息 
        /// </summary> 
        /// <param name="clientSocket"></param> 
        private void ReceiveMessage(object clientSockets)
        {
            Socket myClientSocket = (Socket)clientSockets;

            while (true)
            {
                try
                {
                    //通过clientSocket接收数据 
                    int receiveNumber = myClientSocket.Receive(result);
                    if (receiveNumber == 0) continue;
                    try
                    {
                        var msg = Encoding.UTF8.GetString(result, 0, receiveNumber);
                        if (msg.Trim().Length != 0)
                        {
                            var making = JsonConvert.DeserializeObject<ClientList>(msg);
                            if (making != null)
                            {
                                if (making.code == 4)
                                {
                                    CoffeeSocket = myClientSocket;
                                }
                                else if (making.code == 5)
                                {
                                    IceSocket = myClientSocket;
                                }
                                else if (making.code == 11)
                                {
                                    DPSocket = myClientSocket;
                                    if (DPSocket != null)
                                    {
                                        Thread.Sleep(1000);
                                        ClientList clientList = new ClientList();
                                        MessageClientList coffeelist = MessageClientList.Instance;
                                        clientList.message = coffeelist;
                                        clientList.IsMake = ismake;
                                        DPSocket.Send(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(clientList)));
                                    }
                                }
                                else
                                    clientLists.Add(making);
                            }
                        }
                        Thread.Sleep(10);
                    }
                    catch (Exception)
                    {
                    }
                }
                catch (Exception ex)
                {
                    break;
                }
            }

        }

        public void CoffeeMsg(WuLiaoCoffeeSel wuLiaoCoffee)
        {
            try
            {
                bool ismake = false;
                if (CoffeeMatters.Instance.CoffeeMatter19 != (wuLiaoCoffee.Water_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter19 = wuLiaoCoffee.Water_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter20!= (wuLiaoCoffee.YBJWater_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter20 = wuLiaoCoffee.YBJWater_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter2 != (wuLiaoCoffee.CupFeed1_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter2 = wuLiaoCoffee.CupFeed1_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter3 != (wuLiaoCoffee.CupFeed2_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter3 = wuLiaoCoffee.CupFeed2_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter25 != (wuLiaoCoffee.Print_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter25 = wuLiaoCoffee.Print_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter9 != (wuLiaoCoffee.Milk_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter9 = wuLiaoCoffee.Milk_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter24 != (wuLiaoCoffee.Ice1_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter24 = wuLiaoCoffee.Ice1_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter7 != (wuLiaoCoffee.CoffeeBean_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter7 = wuLiaoCoffee.CoffeeBean_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter8 != (wuLiaoCoffee.CoffeeBean2_Sel_Bol ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter8 = wuLiaoCoffee.CoffeeBean2_Sel_Bol ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter23 != (wuLiaoCoffee.CoffeeWarn ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter23 = wuLiaoCoffee.CoffeeWarn ? 1 : 0;
                if (CoffeeMatters.Instance.CoffeeMatter21 != (wuLiaoCoffee.RobotWarn ? 1 : 0))
                {
                    ismake = true;
                }
                CoffeeMatters.Instance.CoffeeMatter21 = wuLiaoCoffee.RobotWarn ? 1 : 0;
                CoffeeMatters.Instance.CoffeeMatter22 = wuLiaoCoffee.RobotWarn ? 1 : 0;
                // CoffeeMatters.Instance.CoffeeMatter13 = wuLiaoCoffee.CoffeeBean2_Sel_Bol ? 1 : 0;
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    //CCMSDW_B.Background = wuLiaoCoffee.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //CCMSDW_F.Foreground = wuLiaoCoffee.PushRodUP_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //CCMXDW_B.Background = wuLiaoCoffee.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //CCMXDW_F.Foreground = wuLiaoCoffee.PushRodDown_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CCJC_B.Background = wuLiaoCoffee.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CCJC_F.Foreground = wuLiaoCoffee.OutMealCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BJC8_B.Background = wuLiaoCoffee.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BJC8_F.Foreground = wuLiaoCoffee.CupFeed1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BJC12_B.Background = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BJC12_F.Foreground = wuLiaoCoffee.CupFeed2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JBCGJC_B.Background = wuLiaoCoffee.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JBCGJC_F.Foreground = wuLiaoCoffee.TakeCup_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    MILK_B.Background = wuLiaoCoffee.Milk_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    MILK_F.Foreground = wuLiaoCoffee.Milk_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JBCGJC2_B.Background = wuLiaoCoffee.TakeCup2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JBCGJC2_F.Foreground = wuLiaoCoffee.TakeCup2_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BFK8_B.Background = wuLiaoCoffee.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BFK8_F.Foreground = wuLiaoCoffee.LBQFK1_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    BFK12_B.Background = wuLiaoCoffee.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    BFK12_F.Foreground = wuLiaoCoffee.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    //BFK12_B.Background = wuLiaoCoffee.LBQFK2_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    //BFK12_F.Foreground = wuLiaoCoffee.GT1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    SJC_B.Background = wuLiaoCoffee.Water_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    SJC_F.Foreground = wuLiaoCoffee.Water_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    SJC2_B.Background = wuLiaoCoffee.YBJWater_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    SJC2_F.Foreground = wuLiaoCoffee.YBJWater_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    DYJJC_B.Background = wuLiaoCoffee.Print_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    DYJJC_F.Foreground = wuLiaoCoffee.Print_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    CFJJC_B.Background = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    CFJJC_F.Foreground = wuLiaoCoffee.CoffeeWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    JQRJC_B.Background = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    JQRJC_F.Foreground = wuLiaoCoffee.RobotWarn ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));
                    ZBJJC_B.Background = wuLiaoCoffee.Ice1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(19, 220, 40)) : new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    ZBJJC_F.Foreground = wuLiaoCoffee.Ice1_Sel_Bol ? new SolidColorBrush(Color.FromRgb(255, 0, 0)) : new SolidColorBrush(Color.FromRgb(17, 179, 183));

                }));
                if (ismake)
                {
                    TestDelegateInvoke testDelegate = new TestDelegateInvoke(DelegateInvokeMethod);
                    testDelegate.BeginInvoke(null, null);
                }
            }
            catch (Exception)
            {
                return;
            }
        }

        public delegate void TestDelegateInvoke();

        private void DelegateInvokeMethod()
        {
            try
            {
                saveDeviceMatter save = new saveDeviceMatter();
                save.matterStatusJson = JsonConvert.SerializeObject(CoffeeMatters.Instance);
                save.deviceStatusJson = JsonConvert.SerializeObject(deviceStatus.Instance);
                var saves = JsonConvert.SerializeObject(save);
                HttpMsg.Instance.saveDeviceMatterMsg(saves);

            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 单个按钮改变状态
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tag"></param>
        public void DOSelect(string name, double tag)
        {
            try
            {
                switch (name)
                {
                    case "LB8":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LB8_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LB8_IMG.Tag = tag;
                            LB8_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                            //ICECC_CMB.SelectedIndex = tag - 1;
                            //ICECC_CMB.Text = tag.ToString();
                        }));
                        break;
                    case "LB12":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            LB12_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            LB12_IMG.Tag = tag;
                            LB12_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "CCMSS":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMSS_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMSS_IMG.Tag = tag;
                            CCMSS_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "CCMXJ":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            CCMXJ_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            CCMXJ_IMG.Tag = tag;
                            CCMXJ_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GTZ1":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GTZ1_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GTZ1_IMG.Tag = tag;
                            GTZ1_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GTZ2":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GTZ2_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GTZ2_IMG.Tag = tag;
                            GTZ2_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    case "GTZ3":
                        this.Dispatcher.BeginInvoke(new Action(delegate
                        {
                            GTZ3_KG.Text = tag == 1 ? "开(ON)" : "关(OFF)";
                            GTZ3_IMG.Tag = tag;
                            GTZ3_IMG.Source = tag == 1 ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关开.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"开关关.png"));
                        }));
                        break;
                    default:
                        break;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        /// <summary>
        /// 给按钮变颜色
        /// </summary>
        /// <param name="btn">要变颜色得按钮</param>
        /// <param name="type">1，正常 2，接通变1 3，不缺料 4，缺料</param>
        /// <param name="img">要变颜色得按钮 开</param>
        ///  <param name="img1">要变颜色得按钮 关</param>
        public void BtnShow(Button btn, int type, Image img, Image img1)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    if (type == 0)//正常状态do
                    {
                        btn.Tag = 0;
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));

                    }
                    else if (type == 1)//接通变1do
                    {
                        btn.Tag = 1;
                        img1.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                        img.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));
                    }
                }));
            }
            catch (Exception)
            {
                return;
            }
        }

        public void RobotSel_L(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_L.Source = robotMsg.Robot_YKJ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_L.Source = robotMsg.Robot_SD_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_L.Source = robotMsg.Robot_SN_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_L.Source = robotMsg.Robot_YX_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_L.Source = robotMsg.Robot_ZT_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_L.Source = robotMsg.Robot_BJ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_L.Source = robotMsg.Robot_TZ_L ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_L(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotSel_R(RobotMsg robotMsg)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    robot_kj_R.Source = robotMsg.Robot_YKJ_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sd_R.Source = robotMsg.Robot_SD_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_sn_R.Source = robotMsg.Robot_SN_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_yx_R.Source = robotMsg.Robot_YX_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_zt_R.Source = robotMsg.Robot_ZT_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_bj_R.Source = robotMsg.Robot_BJ_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    robot_tz_R.Source = robotMsg.Robot_TZ_R ? new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png")) : new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png")); ;
                    RobotYN_R(robotMsg);
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_L(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                L_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                L_SD.Tag = "0";
                L_BJ.Tag = "0";
                L_BTSD.Tag = "0";
                L_BTXD.Tag = "0";
                L_SSN.Tag = "0";
                L_XSN.Tag = "0";
                L_YXCX.Tag = "0";
                L_ZTCX.Tag = "0";
                L_TZCX.Tag = "0";
                L_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ_L && !robotMsg.Robot_BJ_L && !robotMsg.Robot_YX_L && !robotMsg.Robot_SN_L && !robotMsg.Robot_ZT_L && !robotMsg.Robot_SD_L && !robotMsg.Robot_TZ_L)
                {
                    LTypeKJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ_L)
                {
                    LOpenBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD_L)
                {
                    LCloseBTDY_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BTXD.Tag = "1";
                    L_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN_L)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX_L)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_ZTCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ_L)
                {
                    LOpenYXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_XSN.Tag = "1";
                    L_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT_L)
                {
                    LCloseTZCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_JXCX.Tag = "1";
                    L_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ_L)
                {
                    LTypeBJ_L.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    L_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    L_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        public void RobotYN_R(RobotMsg robotMsg)
        {
            try
            {
                LTypeKJ_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LTypeBJ_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenBTDY_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseBTDY_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenSSN_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LContinueZTCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                LCloseJXCX_R.Background = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                R_SD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BJ.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_SSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                R_SD.Tag = "0";
                R_BJ.Tag = "0";
                R_BTSD.Tag = "0";
                R_BTXD.Tag = "0";
                R_SSN.Tag = "0";
                R_XSN.Tag = "0";
                R_YXCX.Tag = "0";
                R_ZTCX.Tag = "0";
                R_TZCX.Tag = "0";
                R_JXCX.Tag = "0";
                if (!robotMsg.Robot_YKJ_R && !robotMsg.Robot_BJ_R && !robotMsg.Robot_YX_R && !robotMsg.Robot_SN_R && !robotMsg.Robot_ZT_R && !robotMsg.Robot_SD_R && !robotMsg.Robot_TZ_R)
                {
                    LTypeKJ_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_SD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_SD.Tag = "1";
                }
                else if (robotMsg.Robot_YKJ_R)
                {
                    LOpenBTDY_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BTSD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BTSD.Tag = "1";
                }
                else if (robotMsg.Robot_SD_R)
                {
                    LCloseBTDY_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LOpenSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BTXD.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_SSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BTXD.Tag = "1";
                    R_SSN.Tag = "1";
                }
                else if (robotMsg.Robot_SN_R)
                {
                    LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Tag = "1";
                    R_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_YX_R)
                {
                    LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LContinueZTCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_ZTCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_ZTCX.Tag = "1";
                    R_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_TZ_R)
                {
                    LOpenYXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseSSN_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_YXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_XSN.Tag = "1";
                    R_YXCX.Tag = "1";
                }
                else if (robotMsg.Robot_ZT_R)
                {
                    LCloseTZCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    LCloseJXCX_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_JXCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_TZCX.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_JXCX.Tag = "1";
                    R_TZCX.Tag = "1";
                }
                else if (robotMsg.Robot_BJ_R)
                {
                    LTypeBJ_R.Background = new SolidColorBrush(Color.FromRgb(125, 142, 67));
                    R_BJ.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));
                    R_BJ.Tag = "1";
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        #endregion
        private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            try
            {
                // 检查输入的字符是否为数字
                if (!Regex.IsMatch(e.Text, "^[0-9]+$"))
                {
                    e.Handled = true;
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GSCLTime_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("GSCLTime", GSCLTime.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GJCLTime_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("GJCLTime", GJCLTime.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void PCJCLTime_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("PCJCLTime", PCJCLTime.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void NCCLTime_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NCCLTime", NCCLTime.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        //private void GJ_BTN_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        Send("GJ_BTN", GJ1_BTN.Tag.ToString());
        //    }
        //    catch (Exception)
        //    {
        //        return;
        //    }
        //}

        private void GS1_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Send("TGS_BTN", TGS_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void GJ1_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Send("LB_BTN", LB_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void GJ2_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Send("TGX_BTN", TGX_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        //private void GS2_BTN_Click(object sender, RoutedEventArgs e)
        //{
        //    try
        //    {
        //        Send("GS2_BTN", GS2_BTN.Tag.ToString());
        //    }
        //    catch (Exception)
        //    {
        //        return;
        //    }

        //}

        private void GJ3_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                // Send("GJ3_BTN", GJ3_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC1_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC1_BTN", NC1_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC4_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC4_BTN", NC4_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC2_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC2_BTN", NC2_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC5_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC5_BTN", NC5_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC3_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC3_BTN", NC3_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void NC6_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("NC3_BTN", NC3_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void XBB_BTN_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Sends("XBB_BTN", XBB_BTN.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        public int GJ = 0;
        public int GS = 0;
        private void GJW_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                this.Dispatcher.BeginInvoke(new Action(delegate
                {
                    GJ = 0;
                    //GJW_IMG.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"绿圆.png"));
                    //GJZZ1_IMG.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    //GJZZ2_IMG.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                    //GJZZ3_IMG.Source = new BitmapImage(new Uri(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"灰圆.png"));
                }));
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GS2_BTN_Click(object sender, RoutedEventArgs e)
        {

        }

        private void LB8_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("LB8", LB8_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }

        private void LB12_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("LB12", LB12_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void CCMSS_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("CCMSS", CCMSS_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void CCMXJ_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("CCMXJ", CCMXJ_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GTZ1_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("GTZ1", GTZ1_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GTZ2_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("GTZ2", GTZ2_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void GTZ3_IMG_MouseDown(object sender, MouseButtonEventArgs e)
        {
            try
            {
                Send("GTZ3", GTZ3_IMG.Tag.ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime1_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Enter)
                {
                    Send("GT1", (double.TryParse(TTime1.Text.ToString(), out double ttime1) ? ttime1 : 1).ToString());
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime1_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {

                Send("GT1", (double.TryParse(TTime1.Text.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void Test1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("CSGT1", (double.TryParse(TTime1.Text.ToString(), out double ttime1) ? ttime1 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime2_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {

                Send("GT2", (double.TryParse(TTime2.Text.ToString(), out double ttime2) ? ttime2 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void Test2_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("CSGT2", (double.TryParse(TTime2.Text.ToString(), out double ttime2) ? ttime2 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime3_LostFocus(object sender, RoutedEventArgs e)
        {
            try
            {

                Send("GT3", (double.TryParse(TTime3.Text.ToString(), out double ttime3) ? ttime3 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void Test3_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Send("CSGT3", (double.TryParse(TTime3.Text.ToString(), out double ttime3) ? ttime3 : 1).ToString());
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime2_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Enter)
                {
                    Send("GT2", (double.TryParse(TTime2.Text.ToString(), out double ttime2) ? ttime2 : 1).ToString());
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void TTime3_KeyDown(object sender, KeyEventArgs e)
        {
            try
            {
                if (e.Key == Key.Enter)
                {
                    Send("GT3", (double.TryParse(TTime3.Text.ToString(), out double ttime3) ? ttime3 : 1).ToString());
                }
            }
            catch (Exception)
            {
                return;
            }
        }
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            try
            {
                wuliao.Visibility = Visibility.Collapsed;
                CoffeeQuYu.Visibility = Visibility.Collapsed;
                ShangP.Visibility = Visibility.Visible;
            }
            catch (Exception)
            {

                throw;
            }
        }
        public DataTable dgvtb = new DataTable();
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                GoodsAdd add = new GoodsAdd();
                add.UpdBol = false;
                add.ShowDialog();
                if (add.DialogResult == true)
                {
                    DataRow dataRow;
                    dgvtb.Rows.Clear();
                    foreach (var item in goodsMsgs)
                    {
                        dataRow = dgvtb.NewRow();
                        dataRow["sp_Name"] = item.sp_Name;
                        dataRow["sp_Code"] = item.sp_Code;
                        dataRow["CoffeeWZ"] = item.CoffeeWZ;
                        dataRow["CoffeeWZ1"] = item.CoffeeWZ1;
                        dataRow["CoffeeWZ2"] = item.CoffeeWZ2;
                        dataRow["Sugar"] = item.Sugar;
                        dgvtb.Rows.Add(dataRow);
                    }
                    grid1.ItemsSource = dgvtb.DefaultView;
                    File.WriteAllText(GoodsUrl, JsonConvert.SerializeObject(goodsMsgs));
                    Send("SHP", "0");
                }

            }
            catch
            {
            }
        }

        private void Upd_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                GoodsAdd add = new GoodsAdd();
                var dd = grid1.SelectedItem as DataRowView;
                GoodsMsg msg = new GoodsMsg();
                msg.Sugar = dd["Sugar"].ToString();
                msg.CoffeeWZ = Convert.ToInt32(dd["CoffeeWZ"]);
                msg.CoffeeWZ1 = Convert.ToInt32(dd["CoffeeWZ1"]);
                msg.CoffeeWZ2 = Convert.ToInt32(dd["CoffeeWZ2"]);
                msg.sp_Code = dd["sp_Code"].ToString();
                msg.sp_Name = dd["sp_Name"].ToString();
                add.Goods = msg;
                add.UpdBol = true;
                add.ShowDialog();
                if (add.DialogResult == true)
                {
                    DataRow dataRow;
                    dgvtb.Rows.Clear();
                    foreach (var item in goodsMsgs)
                    {
                        dataRow = dgvtb.NewRow();
                        dataRow["sp_Name"] = item.sp_Name;
                        dataRow["sp_Code"] = item.sp_Code;
                        dataRow["CoffeeWZ"] = item.CoffeeWZ;
                        dataRow["CoffeeWZ1"] = item.CoffeeWZ1;
                        dataRow["CoffeeWZ2"] = item.CoffeeWZ2;
                        dataRow["Sugar"] = item.Sugar;
                        dgvtb.Rows.Add(dataRow);
                    }
                    grid1.ItemsSource = dgvtb.DefaultView;
                    File.WriteAllText(GoodsUrl, JsonConvert.SerializeObject(goodsMsgs));
                    Send("SHP", "0");
                }
            }
            catch
            {
            }
        }

        private void Del_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var dd = grid1.SelectedItem as DataRowView;
                goodsMsgs.Remove(goodsMsgs.FirstOrDefault(a => a.sp_Name == dd["sp_Name"].ToString() && a.sp_Code == dd["sp_Code"].ToString() && a.Sugar == dd["Sugar"].ToString() && a.CoffeeWZ == Convert.ToInt32(dd["CoffeeWZ"]) && a.CoffeeWZ1 == Convert.ToInt32(dd["CoffeeWZ1"]) && a.CoffeeWZ2 == Convert.ToInt32(dd["CoffeeWZ2"])));
                DataRow dataRow;
                dgvtb.Rows.Clear();
                foreach (var item in goodsMsgs)
                {
                    dataRow = dgvtb.NewRow();
                    dataRow["sp_Name"] = item.sp_Name;
                    dataRow["sp_Code"] = item.sp_Code;
                    dataRow["CoffeeWZ"] = item.CoffeeWZ;
                    dataRow["CoffeeWZ1"] = item.CoffeeWZ1;
                    dataRow["CoffeeWZ2"] = item.CoffeeWZ2;
                    dataRow["Sugar"] = item.Sugar;
                    dgvtb.Rows.Add(dataRow);
                }
                grid1.ItemsSource = dgvtb.DefaultView;
                File.WriteAllText(GoodsUrl, JsonConvert.SerializeObject(goodsMsgs));
                Send("SHP", "0");
            }
            catch (Exception)
            {

            }
        }
    }
}
